/*
 * Copyright [2020-2030] [https://www.stylefeng.cn]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Guns采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Guns源码头部的版权声明。
 * 3.请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://gitee.com/stylefeng/guns
 * 5.在修改包名，模块名称，项目代码等时，请注明软件出处 https://gitee.com/stylefeng/guns
 * 6.若您的项目无法满足以上几点，可申请商业授权
 */
package com.hbisdt.cet.sample.entity;

import java.io.Serial;
import java.io.Serializable;

/**
 * 碳业务文章咨询数据传输实体
 *
 * @author : 教学示例
 * @version : 1.0
 * @date : 2024-12-10 16:13
 */
public class ResponseData<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 请求是否成功
     */
    private Boolean success;

    /**
     * 响应状态码
     */
    private Integer code;

    /**
     * 响应信息
     */
    private String message;

    /**
     * 响应对象
     */
    private T data;

    /**
     * 操作失败状态码
     */
    public static final Integer FAIL_CODE = -1;

    /**
     * 操作成功状态码
     */
    public static final Integer SUCCESS_CODE = 0;

    /**
     * 执行成功
     *
     * @return com.hbisdt.cet.sample.entity.ResponseData<T>
     * @author : 教学示例
     */
    public static <T> ResponseData<T> ok() {
        ResponseData<T> responseData = new ResponseData<>();
        responseData.setSuccess(true);
        responseData.setCode(SUCCESS_CODE);
        responseData.setMessage("执行成功");
        return responseData;
    }

    /**
     * 执行成功
     *
     * @param data 数据传输对象
     * @return com.hbisdt.cet.sample.entity.ResponseData<T>
     * @author : 教学示例
     */
    public static <T> ResponseData<T> ok(T data) {
        ResponseData<T> responseData = new ResponseData<>();
        responseData.setSuccess(true);
        responseData.setCode(SUCCESS_CODE);
        responseData.setMessage("执行成功");
        responseData.setData(data);
        return responseData;
    }

    /**
     * 操作失败
     *
     * @param msg 错误信息
     * @return com.hbisdt.cet.sample.entity.ResponseData<T>
     * @author : 教学示例
     */
    public static <T> ResponseData<T> failed(String msg) {
        ResponseData<T> responseData = new ResponseData<>();
        responseData.setSuccess(false);
        responseData.setCode(FAIL_CODE);
        responseData.setMessage(msg);
        return responseData;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
